#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time: 2018/1/4 下午2:32
@Author: CZC
@File: parse_gsxt_worker.py
"""
import hashlib
import string

from pyquery import PyQuery

from common import util
from common.global_field import InfoType
from common.gsxt_field import GsModel
from parse_annual_report_worker import ParseAnnualReportWorker


class ParseGsxtWorker(ParseAnnualReportWorker):
    def __init__(self, **kwargs):
        ParseAnnualReportWorker.__init__(self, **kwargs)

    # 基本信息
    def get_base_info(self, base_info):
        """
        :param base_info: 网页库字典, 里面包含list 与 detail 两个列表, 列表中存储的为网页数据
        其中两个列表一定会存在一个, 否则则认为这个数据包无效, list一般储存列表翻页信息, detail存储列表项详情信息
        具体结构参考mongodb网页库或者查看 common/global_field.py 中Model定义注释
        基本信息一般存储在list列表中, 因为基本信息不包含列表结构不需要detail列表
        :return: 返回工商schema字典
        """
        base_info_dict = {}
        page = self.get_crawl_page(base_info)
        if page is None:
            return base_info_dict

        dls = PyQuery(page, parser='html').find('.overview').find('dl').items()
        for dl in dls:
            dt = dl.find('dt').text()
            dd = dl.find('dd').text()
            dt = dt.replace('：', '')
            dt = dt.replace(':', '')
            k = GsModel.format_base_model(dt)
            base_info_dict[k] = dd
        base_info_dict[GsModel.PERIOD] = u"{0}至{1}".format(
            base_info_dict.get(GsModel.PERIOD_FROM, ''), base_info_dict.get(GsModel.PERIOD_TO, ''))
        # 新版工商标记
        base_info_dict.update({GsModel.IS_NEW_GSXT: True})

        return base_info_dict

    # 出资信息
    def get_contributive_info(self, contributive_info):
        contributive_info_dict = {}
        contributive_info_list = []
        contributive_info_dict[GsModel.CONTRIBUTOR_INFORMATION] = contributive_info_list

        pages_list = self.get_crawl_page(contributive_info, True)
        pages_detail = self.get_crawl_page(contributive_info, True, InfoType.type_detail)

        if pages_list is None:
            return contributive_info_dict

        for page in pages_list:
            page_text = page.get('text')
            json_data = util.json_loads(page_text)
            if json_data is None:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:
                # 先解析复杂的数据，股东类型，证照/证件号码
                inv_type_cn = data.get('invType_CN')
                shareholder_type = PyQuery(inv_type_cn, parser='html').remove('div').remove('span'). \
                    text().replace(' ', '').strip() if inv_type_cn else ''
                b_lic_cn = data.get('bLicNo')
                certificate_no = PyQuery(b_lic_cn, parser='html').remove('div').remove('span'). \
                    text().replace(' ', '').strip() if b_lic_cn else ''

                sub_model = {
                    GsModel.ContributorInformation.SHAREHOLDER_NAME: data.get('inv'),
                    GsModel.ContributorInformation.SHAREHOLDER_TYPE: shareholder_type,
                    GsModel.ContributorInformation.CERTIFICATE_TYPE: data.get('blicType_CN'),
                    GsModel.ContributorInformation.CERTIFICATE_NO: certificate_no
                }
                # 出资详情解析
                inv_id = data.get('invId')
                detail_dict = self.get_contributive_info_detail(pages_detail, inv_id)
                sub_model.update(detail_dict)

                contributive_info_list.append(sub_model)

        return contributive_info_dict

    # 主要人员
    def get_key_person_info(self, key_person_info):
        key_person_info_dict = {}
        key_person_info_list = []
        key_person_info_dict[GsModel.KEY_PERSON] = key_person_info_list

        pages_list = self.get_crawl_page(key_person_info, True)
        if not pages_list:
            return key_person_info_dict
        for page in pages_list:
            json_data = util.json_loads(page.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:
                name = data.get('name')
                key_person_name = PyQuery(name, parser='html').remove('span').remove('div').text().replace(" ", "") if name else ''

                # 职位需要进行判断
                position_cn = data.get('position_CN')
                pic_string = util.re_find_one('"([\s\S]*?)"', position_cn)
                md5 = util.get_md5(pic_string)
                key_position = GsModel.get_md5_key_position(md5)
                if not key_position:
                    self.log.error('未发现的新的职位映射：{},company:{}'.format(position_cn, page.get('url')))
                    key_position = position_cn
                key_person = {
                    GsModel.KeyPerson.KEY_PERSON_NAME: key_person_name,
                    GsModel.KeyPerson.KEY_PERSON_POSITION: key_position,
                }
                key_person_info_list.append(key_person)

        return key_person_info_dict

    # 分支机构
    def get_branch_info(self, branch_info):
        """
        :param branch_info: 网页库字典, 里面包含list 与 detail 两个列表, 列表中存储的为网页数据
        其中两个列表一定会存在一个, 否则则认为这个数据包无效, list一般储存列表翻页信息, detail存储列表项详情信息
        具体结构参考mongodb网页库或者查看 common/global_field.py 中Model定义注释
        分支机构一般存储在list列表中, 因为分支机构不包含列表结构不需要detail列表
        :return: 返回工商schema字典
        """
        branch_info_dict = {}
        branch_info_list = []
        branch_info_dict[GsModel.BRANCH] = branch_info_list

        pages_list = self.get_crawl_page(branch_info, True)
        if not pages_list:
            return branch_info_dict
        for page in pages_list:
            json_data = util.json_loads(page.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:
                branch_model = {
                    GsModel.Branch.COMPAY_NAME: data.get('brName'),
                    GsModel.Branch.CODE: data.get('regNo'),
                    GsModel.Branch.REGISTERED_ADDRESS: data.get('regOrg_CN')
                }
                branch_info_list.append(branch_model)

        return branch_info_dict

    # 清算信息
    def get_liquidation_info(self, liquidation_info):
        liquidation_info_dict = {}
        liquidation_info_list = []
        liquidation_info_dict[GsModel.LIQUIDATION_INFO] = liquidation_info_list
        pages_list = self.get_crawl_page(liquidation_info, True)
        if not pages_list:
            return liquidation_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            main_member = ''
            other_member = ''
            for data in data_list:
                if data.get('ligpriSign') == '1':
                    liq_mem = data.get('liqMem')
                    main_member = PyQuery(liq_mem, parser='html').remove('div').text() if liq_mem else ''
                else:
                    liq_mem = data.get('liqMem')
                    other_member = PyQuery(liq_mem, parser='html').remove('div').text() if liq_mem else ''

            liquidation_info_model = {
                GsModel.LiquidationInfo.MAIN_MEMBER: main_member,
                GsModel.LiquidationInfo.OTHER_MEMBER: other_member
            }
            liquidation_info_list.append(liquidation_info_model)

        return liquidation_info_dict

    # 变更信息
    def get_change_info(self, change_info):
        """
        :param change_info: 网页库字典, 里面包含list 与 detail 两个列表, 列表中存储的为网页数据
        其中两个列表一定会存在一个, 否则则认为这个数据包无效, list一般储存列表翻页信息, detail存储列表项详情信息
        具体结构参考mongodb网页库或者查看 common/global_field.py 中Model定义注释
        变更信息一般只包含list列表, 但是特殊情况下也会有detail详情页列表 比如 北京这个省份有发现过包含详情页的变更信息
        :return: 返回工商schema字典
        """
        change_info_dict = {}
        change_info_list = []
        change_info_dict[GsModel.CHANGERECORDS] = change_info_list

        pages_list = self.get_crawl_page(change_info, True)
        if pages_list is None:
            return change_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:
                alt_item_cn = data.get('altItem_CN')
                change_item = PyQuery(alt_item_cn, parser='html').remove('div').remove('span').text()\
                    .replace(' ', '').strip() if alt_item_cn else ''
                change_model = {
                    GsModel.ChangeRecords.CHANGE_ITEM: change_item,
                    GsModel.ChangeRecords.BEFORE_CONTENT: data.get('altBe'),
                    GsModel.ChangeRecords.AFTER_CONTENT: data.get('altAf'),
                    # 日期格式化
                    GsModel.ChangeRecords.CHANGE_DATE: util.convert_time(data.get('altDate'))
                }
                change_info_list.append(change_model)

        return change_info_dict

    # 动产抵押登记信息
    def get_chattel_mortgage_info(self, chattel_mortgage_info):
        """
        :param chattel_mortgage_info: 网页库字典, 里面包含list 与 detail 两个列表, 列表中存储的为网页数据
        其中两个列表一定会存在一个, 否则则认为这个数据包无效, list一般储存列表翻页信息, detail存储列表项详情信息
        具体结构参考mongodb网页库或者查看 common/global_field.py 中Model定义注释
        出资信息一般会由两个列表分别进行存储, 但部分省份也可能只包含list列表, 没有详情页信息
        :return: 返回工商schema字典
        """
        chattel_mortgage_info_dict = {}
        chattel_mortgage_list = []
        chattel_mortgage_info_dict[GsModel.CHATTEL_MORTGAGE_INFO] = chattel_mortgage_list

        pages_list = self.get_crawl_page(chattel_mortgage_info, True)
        pages_detail = self.get_crawl_page(chattel_mortgage_info, True, InfoType.type_detail)
        if not pages_list:
            return chattel_mortgage_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:
                sub_model = {
                    GsModel.ChattelMortgageInfo.REGISTER_NUM: data.get('morRegCNo'),
                    GsModel.ChattelMortgageInfo.REGISTER_DATE: util.convert_time(data.get('regiDate')),
                    GsModel.ChattelMortgageInfo.REGISTER_OFFICE: data.get('regOrg_CN'),
                    GsModel.ChattelMortgageInfo.CREDIT_AMOUNT: util.get_amount_with_unit(data.get('priClaSecAm')),
                    GsModel.ChattelMortgageInfo.STATUS: '有效' if data.get('type') == '1' else '无效',
                    GsModel.ChattelMortgageInfo.PUBLISH_DATE: util.convert_time(data.get('publicDate')),
                }
                # 动产抵押详情页解析
                detail_id = data.get('morReg_Id')
                sub_model[GsModel.ChattelMortgageInfo.CHATTEL_DETAIL] = self.get_chattel_mortgage_info_detail(
                    pages_detail, detail_id)

                chattel_mortgage_list.append(sub_model)

        return chattel_mortgage_info_dict

    # 股权出质登记信息
    def get_equity_pledged_info(self, equity_pledged_info):
        """
        :param equity_pledged_info: 网页库字典, 里面包含list 与 detail 两个列表, 列表中存储的为网页数据
        其中两个列表一定会存在一个, 否则则认为这个数据包无效, list一般储存列表翻页信息, detail存储列表项详情信息
        具体结构参考mongodb网页库或者查看 common/global_field.py 中Model定义注释
        出资信息一般会由两个列表分别进行存储, 但部分省份也可能只包含list列表, 没有详情页信息
        :return: 返回工商schema字典
        """
        equity_pledged_info_dict = {}
        equity_pledged_list = []
        equity_pledged_info_dict[GsModel.EQUITY_PLEDGED_INFO] = equity_pledged_list

        pages_list = self.get_crawl_page(equity_pledged_info, True)
        pages_detail = self.get_crawl_page(equity_pledged_info, True, InfoType.type_detail)

        if not pages_list:
            return equity_pledged_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:
                sub_model = dict()
                register_num = data.get('equityNo').strip() if data.get('equityNo') else ''

                sub_model[GsModel.EquityPledgedInfo.REGISTER_NUM] = register_num
                sub_model[GsModel.EquityPledgedInfo.MORTGAGOR] = data.get('pledgor')
                sub_model[GsModel.EquityPledgedInfo.MORTGAGOR_NUM] = data.get('pledBLicNo')
                sub_model[GsModel.EquityPledgedInfo.PLEDGE_STOCK_AMOUNT] = util.get_amount_with_unit(data.get('impAm'))
                sub_model[GsModel.EquityPledgedInfo.PLEDGEE] = data.get('impOrg')
                sub_model[GsModel.EquityPledgedInfo.PLEDGEE_NUM] = data.get('impOrgBLicNo')
                sub_model[GsModel.EquityPledgedInfo.REGISTER_DATE] = util.convert_time(data.get('equPleDate'))
                sub_model[GsModel.EquityPledgedInfo.STATUS] = '有效' if data.get('type') == '1' else '无效'
                sub_model[GsModel.EquityPledgedInfo.PUBLISH_DATE] = util.convert_time(data.get('publicDate'))

                # 股权出质登记信息详情页解析
                # detail_id = data.get('impOrgId')
                sub_model[GsModel.EquityPledgedInfo.EQUITY_PLEDGED_DETAIL] = self.get_equity_pledged_info_detail(
                    pages_list)

                equity_pledged_list.append(sub_model)
        return equity_pledged_info_dict

    # 知识产权出质登记信息
    def get_intellectual_property_info(self, intellectual_property_info):
        intellectual_property_info_dict = dict()
        intellectual_property_info_list = list()
        # 记录信息 空表也需要
        intellectual_property_info_dict[
            GsModel.INTELLECTUAL_PROPERTY_INFO] = intellectual_property_info_list
        pages_list = self.get_crawl_page(intellectual_property_info, multi=True)
        detail_list = self.get_crawl_page(intellectual_property_info, multi=True, part=InfoType.type_detail)
        if not pages_list:
            return intellectual_property_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get("text"))
            if json_data is None:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue
            for data in data_list:
                kinds = data.get('kinds')
                if kinds == '1':
                    classify = '商标'
                elif kinds == '2':
                    classify = '知识产权'
                else:
                    classify = '其他'

                sub_model = dict()
                sub_model[GsModel.IntellectualPropertyInfo.REGISTER_NUM] = data.get('tmRegNo')
                sub_model[GsModel.IntellectualPropertyInfo.NAME] = data.get('tmName')
                sub_model[GsModel.IntellectualPropertyInfo.CLASSIFY] = classify
                sub_model[GsModel.IntellectualPropertyInfo.MORTGAGOR_NAME] = data.get('pledgor')
                sub_model[GsModel.IntellectualPropertyInfo.PLEDGEE_NAME] = data.get('impOrg')
                sub_model[GsModel.IntellectualPropertyInfo.PLEDGE_REGISTRATION_PERIOD] = '{}至{}'.format(
                    util.convert_time(data.get('pleRegPerFrom')), util.convert_time(data.get('pleRegPerTo')))
                sub_model[GsModel.IntellectualPropertyInfo.STATUS] = '有效' if data.get('type') == '1' else '无效'
                sub_model[GsModel.IntellectualPropertyInfo.PUBLIC_DATE] = util.convert_time(
                    data.get('publicDate'))

                # 详情页解析
                detail_id = data.get('pleId')
                sub_model[GsModel.IntellectualPropertyInfo.DETAIL] = self.get_intellectual_property_info_detail(
                    detail_list, detail_id)

                intellectual_property_info_list.append(sub_model)
        return intellectual_property_info_dict

    # 商标注册信息
    def get_trademark_registration_info(self, trademark_registration_info):
        trademark_registration_info_dict = dict()
        trademark_registration_info_list = list()
        # 记录信息 空表也需要
        trademark_registration_info_dict[GsModel.TRADEMARK_REGISTRATION_INFO] = trademark_registration_info_list
        pages_list = self.get_crawl_page(trademark_registration_info, multi=True)
        if not pages_list:
            return trademark_registration_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:
                sub_model = dict()
                sub_model[GsModel.TrademarkRegistrationInfo.REGISTER_CODE] = data.get('regNum')
                sub_model[GsModel.TrademarkRegistrationInfo.CLASSIFY] = data.get('intCls')
                sub_model[GsModel.TrademarkRegistrationInfo.REGISTER_PUBLIC_DATE] = util.convert_time(data.get('regAnncDate'))
                sub_model[GsModel.TrademarkRegistrationInfo.REGISTER_PUBLIC_CODE] = data.get('regAnncIssue')
                sub_model[GsModel.TrademarkRegistrationInfo.TRADEMARK_PERIOD_DATE] = '{}至{}'.format(
                    util.convert_time(data.get('propertyBgnDate')), util.convert_time(data.get('propertyEndDate')))
                sub_model[GsModel.TrademarkRegistrationInfo.TRADEMARK_OWNERS_INFORMATION] = data.get('coownerCnName')
                sub_model[GsModel.TrademarkRegistrationInfo.TRADEMARK_PATTERN] = 'http://{}/doc/{}/tmfiles/{}'.format(
                    self.host, data.get('nodeNum'), data.get('tmImage')) if data.get('tmImage') else ''
                sub_model[GsModel.TrademarkRegistrationInfo.SERVICE_ITEMS] = data.get('goodsCnName')

                trademark_registration_info_list.append(sub_model)
        return trademark_registration_info_dict

    # 抽查检查结果信息
    def get_spot_check_result_info(self, spot_check_result_info):
        spot_check_result_info_dict = dict()
        spot_check_result_info_list = list()
        # 记录信息 空表也需要
        spot_check_result_info_dict[GsModel.SPOT_CHECK_RESULT_INFO] = spot_check_result_info_list
        pages_list = self.get_crawl_page(spot_check_result_info, multi=True)
        if not pages_list:
            return spot_check_result_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue
            for data in data_list:
                sub_model = dict()
                sub_model[GsModel.SpotCheckResultInfo.CHECK_ENFORCEMENT_OFFICE] = data.get('insAuth_CN')
                sub_model[GsModel.SpotCheckResultInfo.CLASSIFY] = '抽查' if data.get('insType') == '1' else '检查'
                sub_model[GsModel.SpotCheckResultInfo.CHECK_DATE] = util.convert_time(data.get('insDate'))
                sub_model[GsModel.SpotCheckResultInfo.CHECK_RESULT] = data.get('insRes_CN')

                spot_check_result_info_list.append(sub_model)
        return spot_check_result_info_dict

    # 双随机抽查检查结果信息
    def get_double_spot_check_result_info(self, double_spot_check_result_info):
        double_spot_check_result_info_dict = dict()
        double_spot_check_result_info_list = list()
        # 记录信息 空表也需要
        double_spot_check_result_info_dict[GsModel.SPOT_CHECK_RESULT_INFO] = double_spot_check_result_info_list
        pages_list = self.get_crawl_page(double_spot_check_result_info, multi=True)
        detail_list = self.get_crawl_page(double_spot_check_result_info, multi=True, part=InfoType.type_detail)
        if pages_list is None:
            return double_spot_check_result_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue
            for data in data_list:

                sub_model = dict()
                sub_model[GsModel.DoubleSpotCheckResultInfo.SPOT_CHECK_PLAN_NUMBER] = data.get('raninsPlanId')
                sub_model[GsModel.DoubleSpotCheckResultInfo.SPOT_CHECK_PLAN_NAME] = data.get('raninsPlaneName')
                sub_model[GsModel.DoubleSpotCheckResultInfo.SPOT_CHECK_MISSION_NUMBER] = data.get('raninsTaskId')
                sub_model[GsModel.DoubleSpotCheckResultInfo.SPOT_CHECK_MISSION_NAME] = data.get('raninsTaskName')
                sub_model[GsModel.DoubleSpotCheckResultInfo.SPOT_CHECK_TYPE] = data.get('raninsTypeName')
                sub_model[GsModel.DoubleSpotCheckResultInfo.CHECK_OFFICE] = data.get('insAuth')
                sub_model[GsModel.DoubleSpotCheckResultInfo.CHECK_COMPLETION_DATE] = util.convert_time(data.get('insDate'))
                # sub_model[GsModel.DoubleSpotCheckResultInfo.REMARK] = data.get('reMark')

                # 详情页解析
                detail_id = data.get('url')
                sub_model[GsModel.DoubleSpotCheckResultInfo.CHECK_RESULT] = self.get_double_spot_check_result_info_detail(
                    detail_list, detail_id)

                double_spot_check_result_info_list.append(sub_model)
        return double_spot_check_result_info_dict

    # 司法协助信息
    def get_judicial_assistance_info(self, judicial_assistance_info):
        judicial_assistance_info_dict = dict()
        judicial_assistance_info_list = list()
        # 记录信息 空表也需要
        judicial_assistance_info_dict[GsModel.JUDICIAL_ASSISTANCE_INFO] = judicial_assistance_info_list
        pages_list = self.get_crawl_page(judicial_assistance_info, multi=True)
        detail_list = self.get_crawl_page(judicial_assistance_info, multi=True, part=InfoType.type_detail)
        if not pages_list:
            return judicial_assistance_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue
            for data in data_list:
                status_dict = {'0': '', '1': '股权冻结|冻结', '2': '股权冻结|解除冻结', '3': '股权冻结|失效'}
                if data.get('type') == '1':
                    status = status_dict.get(data.get('frozState', '0'))
                    detail_id = data.get('parent_Id')
                else:
                    status = '股权变更'
                    detail_id = data.get('altId')

                sub_model = dict()
                sub_model[GsModel.JudicialAssistanceInfo.BE_EXECUTE_PERSON] = data.get('inv')
                sub_model[GsModel.JudicialAssistanceInfo.STOCK_AMOUNT] = util.get_amount_with_unit(data.get('froAm'))
                sub_model[GsModel.JudicialAssistanceInfo.EXECUTIVE_COURT] = data.get('froAuth')
                sub_model[GsModel.JudicialAssistanceInfo.EXECUTE_CODE] = data.get('executeNo')
                sub_model[GsModel.JudicialAssistanceInfo.STATUS] = status

                # 详情页解析
                sub_model[GsModel.JudicialAssistanceInfo.DETAIL] = self.get_judicial_assistance_info_detail(
                    detail_list, detail_id)

                judicial_assistance_info_list.append(sub_model)
        return judicial_assistance_info_dict

    # 官网提供行政许可信息
    def get_administrative_licensing_info(self, administrative_licensing_info):
        administrative_licensing_info_dict = dict()
        administrative_licensing_info_list = list()
        # 记录信息 空表也需要
        administrative_licensing_info_dict[GsModel.ADMINISTRATIVE_LICENSING_INFO] = administrative_licensing_info_list
        pages_list = self.get_crawl_page(administrative_licensing_info, multi=True)
        if not pages_list:
            return administrative_licensing_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue
            for data in data_list:
                sub_model = dict()
                sub_model[GsModel.AdministrativeLicensingInfo.LICENSE_CODE] = data.get('licNo')
                sub_model[GsModel.AdministrativeLicensingInfo.LICENSE_NAME] = data.get('licName_CN')
                sub_model[GsModel.AdministrativeLicensingInfo.PERIOD_FROM] = util.convert_time(data.get('valFrom'))
                sub_model[GsModel.AdministrativeLicensingInfo.PERIOD_TO] = util.convert_time(data.get('valTo'))
                sub_model[GsModel.AdministrativeLicensingInfo.LICENSE_GOV] = data.get('licAnth')
                sub_model[GsModel.AdministrativeLicensingInfo.LICENSE_CONTENT] = data.get('licItem')

                administrative_licensing_info_list.append(sub_model)
        return administrative_licensing_info_dict

    # 官网提供行政处罚信息
    def get_administrative_penalty_info(self, administrative_penalty_info):
        administrative_penalty_info_dict = dict()
        administrative_penalty_info_list = list()
        # 记录信息 空表也需要
        administrative_penalty_info_dict[GsModel.ADMINISTRATIVE_PENALTY_INFO] = administrative_penalty_info_list
        pages_list = self.get_crawl_page(administrative_penalty_info, multi=True)
        detail_list = self.get_crawl_page(administrative_penalty_info, multi=True, part=InfoType.type_detail)
        if not pages_list:
            return administrative_penalty_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:

                sub_model = dict()
                sub_model[GsModel.AdministrativePenaltyInfo.DECISION_CODE] = data.get('penDecNo')
                sub_model[GsModel.AdministrativePenaltyInfo.CRIMINAL_TYPE] = data.get('illegActType')
                sub_model[GsModel.AdministrativePenaltyInfo.PENALTY_CONTENT] = data.get('penContent')
                sub_model[GsModel.AdministrativePenaltyInfo.DECISION_OFFICE_NAME] = data.get('penAuth_CN')
                sub_model[GsModel.AdministrativePenaltyInfo.PUNISH_DATE] = util.convert_time(data.get('penDecIssDate'))
                sub_model[GsModel.AdministrativePenaltyInfo.PUBLIC_DATE] = util.convert_time(data.get('publicDate'))

                # 详情页解析
                detail_id = data.get('caseId')
                sub_model[GsModel.AdministrativePenaltyInfo.DETAIL] = self.get_administrative_penalty_info_detail(
                    detail_list, detail_id)

                administrative_penalty_info_list.append(sub_model)
        return administrative_penalty_info_dict

    # 列入经营异常名录信息
    def get_abnormal_operation_info(self, abnormal_operation_info):
        abnormal_operation_info_dict = dict()
        abnormal_operation_info_list = list()
        # 记录信息 空表也需要
        abnormal_operation_info_dict[GsModel.ABNORMAL_OPERATION_INFO] = abnormal_operation_info_list

        pages_list = self.get_crawl_page(abnormal_operation_info, multi=True)
        if not pages_list:
            return abnormal_operation_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:
                sub_model = dict()
                sub_model[GsModel.AbnormalOperationInfo.ENROL_REASON] = data.get('speCause_CN')
                sub_model[GsModel.AbnormalOperationInfo.ENROL_DATE] = util.convert_time(data.get('abntime'))
                sub_model[GsModel.AbnormalOperationInfo.ENROL_DECIDE_OFFICE] = data.get('decOrg_CN')
                sub_model[GsModel.AbnormalOperationInfo.REMOVE_REASON] = data.get('remExcpRes_CN')
                sub_model[GsModel.AbnormalOperationInfo.REMOVE_DATE] = util.convert_time(data.get('remDate'))
                sub_model[GsModel.AbnormalOperationInfo.REMOVE_DECIDE_OFFICE] = data.get('reDecOrg_CN')

                abnormal_operation_info_list.append(sub_model)
        return abnormal_operation_info_dict

    # 列入严重违法失信企业名单(黑名单)信息
    def get_illegal_promise_enterprise_info(self, illegal_promise_enterprise_info):
        illegal_promise_enterprise_info_dict = dict()
        illegal_promise_enterprise_info_list = list()
        # 记录信息 空表也需要
        illegal_promise_enterprise_info_dict[GsModel.ILLEGAL_PROMISE_ENTERPRISE_INFO] = illegal_promise_enterprise_info_list
        pages_list = self.get_crawl_page(illegal_promise_enterprise_info, multi=True)
        if not pages_list:
            return illegal_promise_enterprise_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:
                item = dict()
                item[GsModel.IllegalPromiseEnterpriseInfo.CLASSIFY] = data.get('type') if data.get('type') else '严重违法失信企业名单'
                item[GsModel.IllegalPromiseEnterpriseInfo.ENROL_REASON] = data.get('serILLRea_CN')
                item[GsModel.IllegalPromiseEnterpriseInfo.ENROL_DATE] = util.convert_time(data.get('abntime'))
                item[GsModel.IllegalPromiseEnterpriseInfo.ENROL_DECISION_OFFICE] = data.get('decOrg_CN')
                item[GsModel.IllegalPromiseEnterpriseInfo.REMOVE_REASON] = data.get('remExcpRes_CN')
                item[GsModel.IllegalPromiseEnterpriseInfo.REMOVE_DATE] = util.convert_time(data.get('remDate'))
                item[GsModel.IllegalPromiseEnterpriseInfo.REMOVE_DECISION_OFFICE] = data.get('reDecOrg_CN')

                illegal_promise_enterprise_info_list.append(item)
        return illegal_promise_enterprise_info_dict

    # 股东信息
    def get_shareholder_info(self, shareholder_info):
        shareholder_info_dict = {}
        shareholder_info_list = []
        shareholder_info_dict[GsModel.SHAREHOLDER_INFORMATION] = shareholder_info_list

        pages_list = self.get_crawl_page(shareholder_info, multi=True)
        if not pages_list:
            return shareholder_info_dict
        for page in pages_list:
            json_data = util.json_loads(page.get("text"))
            if json_data is None:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:

                share_model = {
                    GsModel.ShareholderInformation.SHAREHOLDER_NAME: data.get('inv'),
                    GsModel.ShareholderInformation.SUBSCRIPTION_AMOUNT: util.get_amount_with_unit(
                        data.get('subSum')),
                    GsModel.ShareholderInformation.PAIED_AMOUNT: util.get_amount_with_unit(
                        data.get('aubSum')),
                }

                subscription_detail_list = []
                paied_detail_list = []
                sub_details = data.get('subDetails')
                aub_details = data.get('aubDetails')
                # 认缴明细
                for sub_item in sub_details:
                    sub_dict = {
                        GsModel.ShareholderInformation.SubscriptionDetail.SUBSCRIPTION_TYPE: sub_item.get(
                            'subConForm_CN'),
                        GsModel.ShareholderInformation.SubscriptionDetail.SUBSCRIPTION_AMOUNT: util.get_amount_with_unit(
                            sub_item.get('subConAmStr')),
                        GsModel.ShareholderInformation.SubscriptionDetail.SUBSCRIPTION_TIME: util.convert_time(sub_item.get('currency')),
                        GsModel.ShareholderInformation.SubscriptionDetail.SUBSCRIPTION_PUBLISH_TIME: util.convert_time(sub_item.get('publicDate')),
                    }
                    subscription_detail_list.append(sub_dict)

                for aub_item in aub_details:
                    paied_dict = {
                        GsModel.ShareholderInformation.PaiedDetail.PAIED_TYPE: aub_item.get('acConFormName'),
                        GsModel.ShareholderInformation.PaiedDetail.PAIED_AMOUNT: util.get_amount_with_unit(
                            aub_item.get('acConAmStr')),
                        GsModel.ShareholderInformation.PaiedDetail.PAIED_TIME: aub_item.get('conDate'),
                        GsModel.ShareholderInformation.PaiedDetail.PAIED_PUBLISH_TIME: aub_item.get('publicDate'),
                    }
                    paied_detail_list.append(paied_dict)

                share_model[GsModel.ShareholderInformation.SUBSCRIPTION_DETAIL] = subscription_detail_list
                share_model[GsModel.ShareholderInformation.PAIED_DETAIL] = paied_detail_list

                shareholder_info_list.append(share_model)
        return shareholder_info_dict

    # 股权变更信息
    def get_change_shareholding_info(self, change_shareholding_info):
        change_shareholding_info_dict = dict()
        change_shareholding_info_list = list()
        # 记录信息 空表也需要
        change_shareholding_info_dict[GsModel.CHANGE_SHAREHOLDING_INFO] = change_shareholding_info_list
        pages_list = self.get_crawl_page(change_shareholding_info, multi=True)
        if not pages_list:
            return change_shareholding_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get("text"))
            if json_data is None:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue
            for data in data_list:
                sub_model = dict()
                sub_model[GsModel.ChangeShareholdingInfo.SHAREHOLDER] = data.get('inv')
                sub_model[GsModel.ChangeShareholdingInfo.CHANGE_BEFORE] = '{}%'.format(data.get('transAmPrBf'))
                sub_model[GsModel.ChangeShareholdingInfo.CHANGE_AFTER] = '{}%'.format(data.get('transAmPrAf'))
                sub_model[GsModel.ChangeShareholdingInfo.CHANGE_DATE] = util.convert_time(data.get('altDate'))
                sub_model[GsModel.ChangeShareholdingInfo.PUBLIC_DATE] = util.convert_time(data.get('publicDate'))

                change_shareholding_info_list.append(sub_model)
        return change_shareholding_info_dict

    # 企业即时行政许可信息
    def get_company_administrative_licensing_info(self, company_administrative_licensing_info):
        company_administrative_licensing_info_dict = dict()
        company_administrative_licensing_info_list = list()
        # 记录信息 空表也需要
        company_administrative_licensing_info_dict[GsModel.COMPANY_ADMINISTRATIVE_LICENSING_INFO] = company_administrative_licensing_info_list
        pages_list = self.get_crawl_page(company_administrative_licensing_info, multi=True)
        detail_list = self.get_crawl_page(company_administrative_licensing_info, multi=True, part=InfoType.type_detail)
        if not pages_list:
            return company_administrative_licensing_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get("text"))
            if json_data is None:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue
            for data in data_list:
                sub_model = dict()
                sub_model[GsModel.CompanyAdministrativeLicensingInfo.LICENSE_CODE] = data.get('licNo')
                sub_model[GsModel.CompanyAdministrativeLicensingInfo.LICENSE_NAME] = data.get('licName_CN')
                sub_model[GsModel.CompanyAdministrativeLicensingInfo.PERIOD_FROM] = util.convert_time(data.get('valFrom'))
                sub_model[GsModel.CompanyAdministrativeLicensingInfo.PERIOD_TO] = util.convert_time(data.get('valTo'))
                sub_model[GsModel.CompanyAdministrativeLicensingInfo.LICENSE_OFFICE] = data.get('licAnth')
                sub_model[GsModel.CompanyAdministrativeLicensingInfo.LICENSE_CONTENT] = data.get('licItem')
                sub_model[GsModel.CompanyAdministrativeLicensingInfo.STATUS] = '有效' if data.get('status') == '1' else '无效'

                # 详情页解析
                detail_id = data.get('licId')
                sub_model[
                    GsModel.CompanyAdministrativeLicensingInfo.DETAIL] = self.get_company_administrative_licensing_info_detail(
                    detail_list, detail_id)

                company_administrative_licensing_info_list.append(sub_model)
        return company_administrative_licensing_info_dict

    # 企业即时知识产权出质登记信息
    def get_company_intellectual_property_info(self, company_intellectual_property_info):
        company_intellectual_property_info_dict = dict()
        company_intellectual_property_info_list = list()
        # 记录信息 空表也需要
        company_intellectual_property_info_dict[GsModel.COMPANY_INTELLECTUAL_PROPERTY_INFO] = company_intellectual_property_info_list
        pages_list = self.get_crawl_page(company_intellectual_property_info, multi=True)
        detail_list = self.get_crawl_page(company_intellectual_property_info, multi=True, part=InfoType.type_detail)
        if not pages_list:
            return company_intellectual_property_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get("text"))
            if json_data is None:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue
            for data in data_list:
                kinds = data.get('kinds')
                if kinds == '1':
                    classify = '商标'
                elif kinds == '2':
                    classify = '版权'
                else:
                    classify = '专利'

                sub_model = dict()
                sub_model[GsModel.CompanyIntellectualPropertyInfo.REGISTER_NUM] = data.get('tmRegNo')
                sub_model[GsModel.CompanyIntellectualPropertyInfo.NAME] = data.get('tmName')
                sub_model[GsModel.CompanyIntellectualPropertyInfo.CLASSIFY] = classify
                sub_model[GsModel.CompanyIntellectualPropertyInfo.MORTGAGOR_NAME] = data.get('pledgor')
                sub_model[GsModel.CompanyIntellectualPropertyInfo.PLEDGEE_NAME] = data.get('impOrg')
                sub_model[GsModel.CompanyIntellectualPropertyInfo.PLEDGE_REGISTRATION_PERIOD] = '{}至{}'.format(
                    util.convert_time(data.get('pleRegPerFrom')), util.convert_time(data.get('pleRegPerTo')))
                sub_model[GsModel.CompanyIntellectualPropertyInfo.STATUS] = '有效' if data.get('type') == '1' else '无效'
                sub_model[GsModel.CompanyIntellectualPropertyInfo.PUBLIC_DATE] = util.convert_time(data.get('publicDate'))

                # 详情页解析
                detail_id = data.get('pleId')
                sub_model[GsModel.CompanyIntellectualPropertyInfo.DETAIL] = self.get_intellectual_property_info_detail(
                    detail_list, detail_id)

                company_intellectual_property_info_list.append(sub_model)
        return company_intellectual_property_info_dict

    # 企业即时行政处罚信息
    def get_company_administrative_penalty_info(self, company_administrative_penalty_info):
        company_administrative_penalty_info_dict = dict()
        company_administrative_penalty_info_list = list()
        # 记录信息 空表也需要
        company_administrative_penalty_info_dict[GsModel.COMPANY_ADMINISTRATIVE_PENALTY_INFO] = company_administrative_penalty_info_list
        pages_list = self.get_crawl_page(company_administrative_penalty_info, multi=True)
        if not pages_list:
            return company_administrative_penalty_info_dict

        for page in pages_list:
            json_data = util.json_loads(page.get("text"))
            if json_data is None:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue
            for data in data_list:

                sub_model = dict()
                sub_model[GsModel.CompanyAdministrativePenaltyInfo.DECISION_CODE] = data.get('penDecNo')
                sub_model[GsModel.CompanyAdministrativePenaltyInfo.CRIMINAL_TYPE] = data.get('illegActType')
                sub_model[GsModel.CompanyAdministrativePenaltyInfo.PENALTY_CONTENT] = data.get('penContent')  # todo 待有case时检查
                sub_model[GsModel.CompanyAdministrativePenaltyInfo.DECISION_OFFICE_NAME] = data.get('judAuth')
                sub_model[GsModel.CompanyAdministrativePenaltyInfo.PUNISH_DATE] = data.get('penDecIssDate')
                sub_model[GsModel.CompanyAdministrativePenaltyInfo.PUBLIC_DATE] = data.get('publicDate')
                sub_model[GsModel.CompanyAdministrativePenaltyInfo.REMARK] = data.get('remark')

                company_administrative_penalty_info_list.append(sub_model)
        return company_administrative_penalty_info_dict

    # 出资信息详情页解析
    @staticmethod
    def get_contributive_info_detail(pages_detail, inv_id):
        contributive_info_detail_dict = {}
        if not inv_id or not pages_detail:
            return contributive_info_detail_dict

        for ear_detail in pages_detail:
            detail_url = ear_detail.get('url')
            if inv_id not in detail_url:
                continue
            detail_text = ear_detail.get('text')
            json_data = util.json_loads(detail_text)
            if not json_data:
                continue

            subscription_list = list()
            paied_list = list()
            subscription_amount = 0
            paied_amount = 0
            data_list = json_data.get('data')
            for data in data_list:
                for item in data:
                    # 认缴
                    if item.get('subId'):
                        subscription_count = item.get('subConAm')
                        subscription_dict = {
                            GsModel.ContributorInformation.SubscriptionDetail.SUBSCRIPTION_TYPE: item.get('conForm_CN'),
                            GsModel.ContributorInformation.SubscriptionDetail.SUBSCRIPTION_AMOUNT: util.get_amount_with_unit(subscription_count),
                            GsModel.ContributorInformation.SubscriptionDetail.SUBSCRIPTION_TIME: util.convert_time(
                                item.get('conDate'))
                        }
                        if isinstance(subscription_count, int):
                            subscription_amount += subscription_count
                        subscription_list.append(subscription_dict)

                    # 实缴
                    if item.get('acId'):
                        paied_count = item.get('acConAm')
                        paied_dict = {
                            GsModel.ContributorInformation.PaiedDetail.PAIED_TYPE: item.get('conForm_CN'),
                            GsModel.ContributorInformation.PaiedDetail.PAIED_AMOUNT: util.get_amount_with_unit(paied_count),
                            GsModel.ContributorInformation.PaiedDetail.PAIED_TIME: util.convert_time(
                                item.get('conDate'))
                        }
                        if isinstance(paied_count, int):
                            paied_amount += paied_count
                        paied_list.append(paied_dict)

            contributive_info_detail_dict[GsModel.ContributorInformation.SUBSCRIPTION_AMOUNT] = util.get_amount_with_unit(subscription_amount)
            contributive_info_detail_dict[GsModel.ContributorInformation.PAIED_AMOUNT] = util.get_amount_with_unit(paied_amount)
            contributive_info_detail_dict[GsModel.ContributorInformation.SUBSCRIPTION_DETAIL] = subscription_list
            contributive_info_detail_dict[GsModel.ContributorInformation.PAIED_DETAIL] = paied_list
        return contributive_info_detail_dict

    # 动产抵押详情页解析
    @staticmethod
    def get_chattel_mortgage_info_detail(pages_detail, detail_id):
        chattel_mortgage_detail_dict = {}
        if not detail_id or not pages_detail:
            return chattel_mortgage_detail_dict

        same_list = []  # 存放相同item的5个url
        for detail in pages_detail:

            detail_url = detail.get('url')
            if detail_id in detail_url:
                same_list.append(detail)

        for ear_detail in same_list:
            detail_text = ear_detail.get('text')
            json_data = util.json_loads(detail_text)
            if not json_data:
                continue
            ear_detail_url = ear_detail.get('url')

            if 'getMortRegCancelInfo' in ear_detail_url:
                json_data = json_data.get('data')
                if not json_data:
                    continue
                if len(json_data) == 0:
                    continue
                json_data = json_data[0]

                # 动产抵押登记信息
                cm_dict = dict()
                chattel_mortgage_detail_dict[GsModel.ChattelMortgageInfo.ChattelDetail.CHATTEL_MORTGAGE] = cm_dict
                cm_dict[GsModel.ChattelMortgageInfo.ChattelDetail.ChattelMortgage.REGISTER_NUM] = json_data.get('morRegCNo')
                cm_dict[GsModel.ChattelMortgageInfo.ChattelDetail.ChattelMortgage.REGISTER_DATE] = util.convert_time(json_data.get('regiDate'))
                cm_dict[GsModel.ChattelMortgageInfo.ChattelDetail.ChattelMortgage.REGISTER_OFFICE] = json_data.get('regOrg_CN')

                # 注销信息
                item = dict()
                chattel_mortgage_detail_dict[GsModel.ChattelMortgageInfo.ChattelDetail.CANCEL_INFO] = item
                item[GsModel.ChattelMortgageInfo.ChattelDetail.CancelInfo.CANCEL_DATE] = util.convert_time(json_data.get('canDate'))
                item[GsModel.ChattelMortgageInfo.ChattelDetail.CancelInfo.CANCEL_REASON] = json_data.get('morCanRea_CN')

            # 抵押权人概况信息
            elif 'mortregpersoninfo' in ear_detail_url:
                json_data = json_data.get('data')
                if not json_data:
                    continue

                mps_list = list()
                chattel_mortgage_detail_dict[
                    GsModel.ChattelMortgageInfo.ChattelDetail.MORTGAGE_PERSON_STATUS] = mps_list
                for obj in json_data:
                    item = dict()
                    item[
                        GsModel.ChattelMortgageInfo.ChattelDetail.MortgagePersonStatus.MORTGAGE_PERSON_NAME] = obj.get(
                        'more')
                    item[GsModel.ChattelMortgageInfo.ChattelDetail.MortgagePersonStatus.CERTIFICATE_TYPE] = obj.get(
                        'bLicType_CN')
                    item[GsModel.ChattelMortgageInfo.ChattelDetail.MortgagePersonStatus.CERTIFICATE_NUM] = obj.get(
                        'bLicNo')
                    mps_list.append(item)

            # 被担保主债权信息
            elif 'mortCreditorRightInfo' in ear_detail_url:
                json_data = json_data.get('data')
                if not json_data:
                    continue
                if len(json_data) < 1:
                    continue
                json_data = json_data[0]

                gps_dict = dict()
                chattel_mortgage_detail_dict[
                    GsModel.ChattelMortgageInfo.ChattelDetail.GUARANTEED_PERSON_STATUS] = gps_dict
                gps_dict[GsModel.ChattelMortgageInfo.ChattelDetail.GuaranteedPersonStatus.KIND] = json_data.get(
                    'priClaSecKind_CN')
                gps_dict[
                    GsModel.ChattelMortgageInfo.ChattelDetail.GuaranteedPersonStatus.AMOUNT] = util.get_amount_with_unit(
                    json_data.get('priClaSecAm'))  # todo 单位映射表
                gps_dict[GsModel.ChattelMortgageInfo.ChattelDetail.GuaranteedPersonStatus.SCOPE] = json_data.get(
                    'warCov')
                gps_dict[
                    GsModel.ChattelMortgageInfo.ChattelDetail.GuaranteedPersonStatus.PERIOD] = '{}至{}'.format(
                    util.convert_time(json_data.get('pefPerForm')), util.convert_time(json_data.get('pefPerTo')))
                gps_dict[GsModel.ChattelMortgageInfo.ChattelDetail.GuaranteedPersonStatus.REMARK] = json_data.get(
                    'remark')

            # 抵押物信息
            elif 'mortGuaranteeInfo' in ear_detail_url:
                json_data = json_data.get('data')
                if not json_data:
                    continue

                gs_list = list()
                chattel_mortgage_detail_dict[
                    GsModel.ChattelMortgageInfo.ChattelDetail.GUARANTEE_STATUS] = gs_list
                for obj in json_data:
                    item = dict()
                    item[GsModel.ChattelMortgageInfo.ChattelDetail.GuaranteeStatus.NAME] = obj.get('guaName')
                    item[GsModel.ChattelMortgageInfo.ChattelDetail.GuaranteeStatus.AFFILIATION] = obj.get('own')
                    item[GsModel.ChattelMortgageInfo.ChattelDetail.GuaranteeStatus.SITUATION] = obj.get('guaDes')
                    item[GsModel.ChattelMortgageInfo.ChattelDetail.GuaranteeStatus.REMARK] = obj.get('remark')
                    gs_list.append(item)

            # 变更信息
            elif 'getMortAltItemInfo' in ear_detail_url:
                json_data = json_data.get('data')
                if not json_data:
                    continue
                change_list = list()
                chattel_mortgage_detail_dict[GsModel.ChattelMortgageInfo.ChattelDetail.CHANGE_INFO] = change_list

                for data in json_data:
                    item = dict()
                    item[GsModel.ChattelMortgageInfo.ChattelDetail.ChangeInfo.CHANGE_DATE] = util.convert_time(data.get('altDate'))
                    item[GsModel.ChattelMortgageInfo.ChattelDetail.ChangeInfo.CHANGE_CONTENT] = data.get('alt')
                    change_list.append(item)

        return chattel_mortgage_detail_dict

    # 股权出质登记信息详情页解析
    @staticmethod
    def get_equity_pledged_info_detail(pages_list):
        equity_pledged_detail_dict = {}
        if not pages_list:
            return equity_pledged_detail_dict

        for detail in pages_list:
            json_data = util.json_loads(detail.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:
                alt_list = data.get('vStakQualitInfoAlt')
                # 变更信息
                if alt_list:
                    change_list = list()
                    equity_pledged_detail_dict[
                        GsModel.EquityPledgedInfo.EquityPledgedDetail.CHANGE_INFO] = change_list
                    for alt in alt_list:
                        item = dict()
                        item[GsModel.EquityPledgedInfo.EquityPledgedDetail.ChangeInfo.CHANGE_DATE] = util.convert_time(alt.get('altDate'))
                        item[GsModel.EquityPledgedInfo.EquityPledgedDetail.ChangeInfo.CHANGE_CONTENT] = alt.get('alt')
                        change_list.append(item)
                else:
                    # 注销信息
                    item = dict()
                    equity_pledged_detail_dict[GsModel.EquityPledgedInfo.EquityPledgedDetail.CANCEL_INFO] = item
                    item[
                        GsModel.EquityPledgedInfo.EquityPledgedDetail.CancelInfo.CANCEL_DATE] = util.convert_time(
                        data.get('canDate'))
                    item[GsModel.EquityPledgedInfo.EquityPledgedDetail.CancelInfo.CANCEL_REASON] = data.get(
                        'equPleCanRea')
        return equity_pledged_detail_dict

    # 双随机抽查检查结果信息详情页解析
    @staticmethod
    def get_double_spot_check_result_info_detail(detail_list, detail_id):
        double_spot_check_result_info_detail_dict = {}
        info_list = list()
        double_spot_check_result_info_detail_dict[GsModel.DoubleSpotCheckResultInfo.CHECK_RESULT] = info_list
        if not detail_id or not detail_list:
            return double_spot_check_result_info_detail_dict

        for detail in detail_list:

            detail_url = detail.get('url')
            if not isinstance(detail_url, basestring):
                continue
            if detail_id not in detail_url:
                continue

            json_data = util.json_loads(detail.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:
                sub_model = dict()
                sub_model[GsModel.DoubleSpotCheckResultInfo.CheckResult.CHECK_ITEM] = data.get('raninsItemName')
                sub_model[GsModel.DoubleSpotCheckResultInfo.CheckResult.CHECK_RESULT] = data.get('raninsCheckResName')

                info_list.append(sub_model)
        return double_spot_check_result_info_detail_dict

    # 司法协助信息详情页解析
    @staticmethod
    def get_judicial_assistance_info_detail(detail_list, detail_id):
        judicial_assistance_info_detail_dict = {}
        if not detail_id or not detail_list:
            return judicial_assistance_info_detail_dict
        for detail in detail_list:

            detail_url = detail.get('url')
            if not isinstance(detail_url, basestring):
                continue
            if detail_id not in detail_url:
                continue

            json_data = util.json_loads(detail.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:
                if data.get('frozState') == '1':
                    item = dict()
                    judicial_assistance_info_detail_dict[GsModel.JudicialAssistanceInfo.Detail.FROZEN_SITUATION] = item
                    item[GsModel.JudicialAssistanceInfo.Detail.FrozenSituation.EXECUTIVE_COURT] = data.get('froAuth')
                    item[GsModel.JudicialAssistanceInfo.Detail.FrozenSituation.EXECUTE_ITEM] = data.get('executeItem_CN')
                    item[GsModel.JudicialAssistanceInfo.Detail.FrozenSituation.EXECUTE_ORDER_CODE] = data.get('froDocNo')
                    item[GsModel.JudicialAssistanceInfo.Detail.FrozenSituation.EXECUTE_NOTICE_CODE] = data.get('executeNo')
                    item[GsModel.JudicialAssistanceInfo.Detail.FrozenSituation.BE_EXECUTE_PERSON] = data.get('inv')
                    item[GsModel.JudicialAssistanceInfo.Detail.FrozenSituation.STOCK_AMOUNT] = util.get_amount_with_unit(data.get('froAm'))
                    item[GsModel.JudicialAssistanceInfo.Detail.FrozenSituation.LICENSE_TYPE] = data.get('cerType_CN')
                    item[GsModel.JudicialAssistanceInfo.Detail.FrozenSituation.LICENSE_NUM] = data.get('cerNo')
                    item[GsModel.JudicialAssistanceInfo.Detail.FrozenSituation.FROZEN_DATE_FROM] = util.convert_time(data.get('froFrom'))
                    item[GsModel.JudicialAssistanceInfo.Detail.FrozenSituation.FROZEN_DATE_TO] = util.convert_time(data.get('froTo'))
                    item[GsModel.JudicialAssistanceInfo.Detail.FrozenSituation.FROZEN_PERIOD_DATE] = util.convert_time(data.get('frozDeadline'))
                    item[GsModel.JudicialAssistanceInfo.Detail.FrozenSituation.PUBLISH_DATE] = util.convert_time(data.get('publicDate'))

                elif data.get('frozState') == '2':
                    item = dict()
                    judicial_assistance_info_detail_dict[
                        GsModel.JudicialAssistanceInfo.Detail.THAW_SITUATION] = item
                    item[GsModel.JudicialAssistanceInfo.Detail.ThawSituation.EXECUTIVE_COURT] = data.get('froAuth')
                    item[GsModel.JudicialAssistanceInfo.Detail.ThawSituation.EXECUTE_ITEM] = data.get('executeItem_CN')
                    item[GsModel.JudicialAssistanceInfo.Detail.ThawSituation.EXECUTE_ORDER_CODE] = data.get('froDocNo')
                    item[GsModel.JudicialAssistanceInfo.Detail.ThawSituation.EXECUTE_NOTICE_CODE] = data.get('executeNo')
                    item[GsModel.JudicialAssistanceInfo.Detail.ThawSituation.BE_EXECUTE_PERSON] = data.get('inv')
                    item[GsModel.JudicialAssistanceInfo.Detail.ThawSituation.STOCK_AMOUNT] = util.get_amount_with_unit(data.get('froAm'))
                    item[GsModel.JudicialAssistanceInfo.Detail.ThawSituation.LICENSE_TYPE] = data.get('bLicType_CN')
                    item[GsModel.JudicialAssistanceInfo.Detail.ThawSituation.LICENSE_NUM] = data.get('bLicNo')
                    item[GsModel.JudicialAssistanceInfo.Detail.ThawSituation.THAW_DATE] = util.convert_time(data.get('thawDate'))
                    item[GsModel.JudicialAssistanceInfo.Detail.ThawSituation.PUBLISH_DATE] = util.convert_time(data.get('publicDate'))

                elif data.get('frozState') == '3':
                    item = dict()
                    judicial_assistance_info_detail_dict[
                        GsModel.JudicialAssistanceInfo.Detail.FAILURE] = item
                    item[GsModel.JudicialAssistanceInfo.Detail.Failure.FAILURE_REASON] = data.get('loseEffRes_CN')
                    item[GsModel.JudicialAssistanceInfo.Detail.Failure.FAILURE_DATE] = util.convert_time(data.get('loseEffDate'))

                else:
                    item = dict()
                    judicial_assistance_info_detail_dict[
                        GsModel.JudicialAssistanceInfo.Detail.SHAREHOLDERS_CHANGE] = item
                    item[GsModel.JudicialAssistanceInfo.Detail.ShareholdersChange.EXECUTIVE_COURT] = data.get('froAuth')
                    item[GsModel.JudicialAssistanceInfo.Detail.ShareholdersChange.EXECUTE_ITEM] = '强制转让被执行人股权，办理有限责任公司股东变更登记'
                    item[GsModel.JudicialAssistanceInfo.Detail.ShareholdersChange.EXECUTE_ORDER_CODE] = data.get('froDocNo')
                    item[GsModel.JudicialAssistanceInfo.Detail.ShareholdersChange.EXECUTE_NOTICE_CODE] = data.get('executeNo')
                    item[GsModel.JudicialAssistanceInfo.Detail.ShareholdersChange.BE_EXECUTE_PERSON] = data.get('inv')
                    item[GsModel.JudicialAssistanceInfo.Detail.ShareholdersChange.STOCK_AMOUNT] = util.get_amount_with_unit(data.get('froAm'))
                    item[GsModel.JudicialAssistanceInfo.Detail.ShareholdersChange.LICENSE_TYPE] = data.get('invBLicType_CN')
                    item[GsModel.JudicialAssistanceInfo.Detail.ShareholdersChange.LICENSE_NUM] = data.get('invBLicNo')
                    item[GsModel.JudicialAssistanceInfo.Detail.ShareholdersChange.RECEIVING_PERSON] = data.get('alien')
                    item[GsModel.JudicialAssistanceInfo.Detail.ShareholdersChange.ASSIST_EXECUTION_DATE] = util.convert_time(data.get('executeDate'))
                    item[GsModel.JudicialAssistanceInfo.Detail.ShareholdersChange.RECEIVING_PERSON_LICENSE_TYPE] = data.get('alienCerType_CN')
                    item[GsModel.JudicialAssistanceInfo.Detail.ShareholdersChange.RECEIVING_PERSON_LICENSE_NUM] = data.get('alienCerNo')

        return judicial_assistance_info_detail_dict

    # 行政处罚信息详情页解析
    @staticmethod
    def get_administrative_penalty_info_detail(detail_list, detail_id):
        administrative_penalty_info_detail_dict = {}
        if not detail_id:
            return administrative_penalty_info_detail_dict

        # if detail_list is not None:
        #     for detail in detail_list:
        #
        #         detail_url = detail.get('url')
        #         if not isinstance(detail_url, basestring):
        #             continue
        #         if detail_id not in detail_url:
        #             continue
        #
        #         detail_text = detail.get(u'text', u'')
        #         table = PyQuery(detail_text, parser='html').find('#xzcf_file')
        #
        #         item = dict()
        #         administrative_penalty_info_detail_dict[GsModel.AdministrativePenaltyInfo.DETAIL] = item
        #         item[GsModel.AdministrativePenaltyInfo.Detail.PENALTY_DECISION] = table.text()

        return administrative_penalty_info_detail_dict

    # 企业即时行政许可信息详情页解析
    # todo 暂无发现详情案例
    @staticmethod
    def get_company_administrative_licensing_info_detail(detail_list, detail_id):
        company_administrative_licensing_info_detail_dict = dict()
        info_list = list()
        company_administrative_licensing_info_detail_dict[GsModel.DoubleSpotCheckResultInfo.CHECK_RESULT] = info_list
        if not detail_id or not detail_list:
            return company_administrative_licensing_info_detail_dict

        for detail in detail_list:

            detail_url = detail.get('url')
            if not isinstance(detail_url, basestring):
                continue
            if detail_id not in detail_url:
                continue

            json_data = util.json_loads(detail.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for data in data_list:
                sub_model = dict()
                sub_model[GsModel.CompanyAdministrativeLicensingInfo.Detail.CHANGE_ITEM] = data.get('alt')
                sub_model[GsModel.CompanyAdministrativeLicensingInfo.Detail.CHANGE_DATE] = util.convert_time(data.get('altDate'))
                sub_model[GsModel.CompanyAdministrativeLicensingInfo.Detail.BEFORE_CONTENT] = data.get('altBe')
                sub_model[GsModel.CompanyAdministrativeLicensingInfo.Detail.AFTER_CONTENT] = data.get('altAf')

                info_list.append(sub_model)
        return company_administrative_licensing_info_detail_dict

    # 知识产权出质登记信息详情页解析
    @staticmethod
    def get_intellectual_property_info_detail(detail_list, detail_id):
        intellectual_property_info_detail_dict = {}
        if not detail_id or not detail_list:
            return intellectual_property_info_detail_dict
        for detail in detail_list:

            detail_url = detail.get('url')
            if not isinstance(detail_url, basestring):
                continue
            if detail_id not in detail_url:
                continue

            json_data = util.json_loads(detail.get('text'))
            if not json_data:
                continue
            data_list = json_data.get('data')
            if not data_list:
                continue

            for index, data in enumerate(data_list):
                if data.get('type') == '1':
                    if index == 0:
                        item = list()
                        intellectual_property_info_detail_dict[GsModel.CompanyIntellectualPropertyInfo.Detail.CHANGE_INFO] = item

                    item_dict = dict()
                    item_dict[GsModel.CompanyIntellectualPropertyInfo.Detail.ChangeInfo.CHANGE_ITEM] = data.get('alt')
                    item_dict[GsModel.CompanyIntellectualPropertyInfo.Detail.ChangeInfo.CHANGE_DATE] = util.convert_time(data.get('altDate'))
                    item_dict[GsModel.CompanyIntellectualPropertyInfo.Detail.ChangeInfo.BEFORE_CONTENT] = data.get('altBe')
                    item_dict[GsModel.CompanyIntellectualPropertyInfo.Detail.ChangeInfo.AFTER_CONTENT] = data.get('altAf')
                    item.append(item_dict)  # 为了兼顾变更信息是list的结构

                elif data.get('frozState') == '2':
                    item = dict()
                    intellectual_property_info_detail_dict[GsModel.CompanyIntellectualPropertyInfo.Detail.CANCEL_INFO] = item
                    item[GsModel.CompanyIntellectualPropertyInfo.Detail.CancelInfo.CANCEL_DATE] = util.convert_time(data.get('canDate'))
                    item[GsModel.CompanyIntellectualPropertyInfo.Detail.CancelInfo.CANCEL_REASON] = data.get('equPleCanRea')

                else:
                    item = dict()
                    intellectual_property_info_detail_dict[GsModel.CompanyIntellectualPropertyInfo.Detail.OTHER_INFO] = item
                    item[GsModel.CompanyIntellectualPropertyInfo.Detail.OtherInfo.INVALID_DATE] = util.convert_time(data.get('invalidDate'))
                    item[GsModel.CompanyIntellectualPropertyInfo.Detail.OtherInfo.INVALID_REASON] = data.get('invalidRea')

        return intellectual_property_info_detail_dict
